<?php
session_start();
if($_SERVER['REQUEST_METHOD'] != "POST") {
//if(!isset($_POST['submit'])){
    exit('非法访问!');
}
$haveid=$_POST['haveid'];
$address = $_POST['address'];
$mobile = $_POST['mobile'];
$consignee = $_POST['consignee'];
$phone = $_POST['phone'];
$userid=$_SESSION['userid'];
//包含数据库连接文件
include('system/db/conn.php');
//检测默认地址是否存在
if(is_null($haveid)||$haveid==""){
$isdefult="1";
$check_query = mysql_query("select id from do_user_consignee where user_id=".$userid." and isdefult='1' limit 1");

if(mysql_fetch_array($check_query)){
  $isdefult="0";
}


//写入数据
$sql = "INSERT INTO do_user_consignee(address,mobile,consignee,phone,isdefult,user_id)VALUES('$address','$mobile','$consignee',
'$phone','$isdefult',$userid)";
if(mysql_query($sql,$conn)){
	header('location:member-add.php');
    //exit('用户注册成功！点击此处 <a href="index.php">首页</a>');
} else {
	//echo '<script language=\"JavaScript\">alert(\"抱歉！添加数据失败:',mysql_error(),'\");</script>'; 
    echo '抱歉！添加地址失败：',mysql_error(),'<br />';
    echo '点击此处 <a href="javascript:history.back(-1);">返回</a> 重试';
}

}else{

$sql = "update do_user_consignee set address='$address',mobile='$mobile',consignee='$consignee',phone='$phone' where id=".$haveid;

if(mysql_query($sql,$conn)){
	header('location:member-add.php');
}


}
?>